﻿
using System;
using System.Configuration;
using System.Windows.Forms;


namespace CmdPrep.Frontends
{
    public partial class ProgramSettingsForm : Form
    {
        public ProgramSettingsForm()
        {
            InitializeComponent();
        }
        
        public void editProgramSettings(ApplicationSettingsBase programSettings)
        {
            programSettingsPropertyGrid.SelectedObject = programSettings;
            this.Show();
        }
        
        void handleButtonClick(object sender, EventArgs e)
        {            
            ApplicationSettingsBase programSettings = 
                programSettingsPropertyGrid.SelectedObject as ApplicationSettingsBase;
            
            if (programSettings != null)
            {
                if (sender == defaultsButton)
                    programSettings.Reset();
                
                if ((sender == reloadButton) || (sender == cancelButton))
                    programSettings.Reload();
                
                if ((sender == defaultsButton) || (sender == reloadButton) || (sender == cancelButton))
                    programSettingsPropertyGrid.SelectedObject = programSettings; // Resync
                
                if (sender == okButton)
                    programSettings.Save();
            }
            
            if ((sender == okButton) || (sender == cancelButton))
                this.Hide();            
        }
    }
}
